package com.tingyuge.base.structrue.stack;

import com.sun.javafx.image.PixelUtils;

/**
 * @Created by xiaodao
 */
public class ArrayStack<E> implements Stack<E> {

    Array<E> array;

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public void push(E e) {
        array.addLast(e);

    }

    @Override
    public E peek() {
        return array.getLast();
    }

    @Override
    public E pop() {
        return array.removeLast();
    }

    public ArrayStack(int capacity){
        array = new Array<>(capacity);
    }

    public ArrayStack(){
        array = new Array<>();
    }

    public int getCapacity(){
      return   array.getCapacity();
    }


    @Override
    public String toString() {
        StringBuilder builder =new StringBuilder();
        builder.append("Stack: ");
        builder.append("[");
        for (int i = 0; i < array.getSize(); i++) {
            builder.append(array.get(i));
            if(i != (array.getSize()-1))
                builder.append(", ");

        }
        builder.append("] top");
        return builder.toString();
    }
}
